<?php
/**
this plugin for create resource url to br request
@param host     string [optional] ,if crossdomain
@param type     string type = image | model | video | icon
@param size     string size = mini | medium | large
@param id       int resource id
@param business_id the business_id to get resource
@param random   true | false , is random

*/
function smarty_function_convertlink ($params, &$smarty) 
{
    $data = $params['data'];
    $topic_uid = $params['topic_uid'];
/*
    if($topic_uid == 2){
      $modifiedText = $data;
    }else{
      $modifiedText = preg_replace_callback('@<a(?:.*)>(.*)</a>@isU', 'findAndReplace', $data);
    }
*/
      $modifiedText = preg_replace_callback('@<a(?:.*)>(.*)</a>@isU', 'findAndReplace', $data);

    echo $modifiedText;
}



function findAndReplace($arr) {
  //var_dump($arr);
  global $cleanInputText;
  static $ct = 0;
  $ct++;

  $replaceArray = explode('href="',$arr[0]);


  if(isset($replaceArray[1]) && trim($replaceArray[1]) != "" && strlen($replaceArray[1])>0){
    $httpHeadExplode = explode('http://',$replaceArray[1]);
    //var_dump($httpHeadExplode);
    if(isset($httpHeadExplode[1]) && trim($httpHeadExplode[1]) != "" && strlen($httpHeadExplode[1])>0){
        $httpTrailExplode = explode('">',$httpHeadExplode[1]);
     }else{
        $httpTrailExplode = explode('">',$httpHeadExplode[0]);
     }

  }

  if(isset($httpTrailExplode[0]) && trim($httpTrailExplode[0]) != "" && strlen($httpTrailExplode[0])>0){
    $page = htmlentities($httpTrailExplode[0]);
    //$page = $httpTrailExplode[0];
    $trailPage = '">'.$httpTrailExplode[1];
   }else{
    $page = $httpHeadExplode[1];
   }

  $replaceArray[1] = "index.php?module=InnoForum&func=page&ctrl=redirect&page=".$page."".$trailPage;

  $text = implode('href="',$replaceArray);

  return $text;

}

